#!/usr/bin/python
###### 20 december 2013 kurgan sity russia Coloveov di ###########
import sys
##############
scl = 7
##############
f_o = open("soch1","r")
print "%!PS-Adobe-3.0 EPSF-3.0"
def readl():
	global r_l
	r_l = f_o.readline()
def text():
	global r_l
	print "/Times-Roman findfont"
	print str(size) +" scalefont"
	print "setfont"
	print "newpath"
	print str(x)+ " " + str(y) + " " + " moveto"
	print "( "+r_l+ " ) show"
readl()
size = scl*1.5
x = 25*scl
y = 85*scl
text()
readl()
size = scl*1.2
x = 40*scl
y = 83*scl
text()
readl()
def massr():
	global mass
	mass = r_l.split()
i = 0
pos_x = scl*3
pos_y = 75 * scl
shag = scl * 2
def noten():
	global Fd,Gd,Ad,Bd,C,D,E,F,G,A,B,c,d,e,f,g,a,b
	Fd = pos_y - scl*2	
	Gd = pos_y - scl*1.5
	Ad = pos_y - scl*1
	Bd = pos_y - scl*0.5
	C = pos_y + scl*0
	D = pos_y + scl*0.5
	E = pos_y + scl*1
	F = pos_y + scl*1.5
	G = pos_y + scl*2
	A = pos_y + scl*2.5
	B = pos_y + scl*3
	c = pos_y + scl*3.5
	d = pos_y + scl*4
	e = pos_y + scl*4.5
	f = pos_y + scl*5
	g = pos_y + scl*5.5
	a = pos_y + scl*6
	b = pos_y + scl*6.5
noten()
cup = 750 + 10
fill = True
diez = False
dpal = False
dobup = True
vniz = False
trez = False
toch = False
bar = False
bemol = False
becar = False
fill = True
dobd = False
alter = False
liga = False
single = False
sv = True
plusp = 0
def nota():
########################################nota#################################################
		global pos_x,notta,dobd,fill,diez,dpal,dobup,cup,bemol,becar,toch,alter,plusp,single
		if fill == True:
			print "newpath"
        		print str(pos_x) + " " + str(notta) + " " + str(scl/2)+" 0 360 arc closepath"
        		print "0 0 0 setgray fill"
        		print "stroke"
			if toch == True:
				print "newpath"
        			print str(pos_x+shag/2) + " " + str(notta) + " " + "1.3 0 360 arc closepath"
				print "0 0 0 setgray fill"
				print "0.5 setlinewidth"
        			print "stroke"
		else:
			print "newpath"
        		print str(pos_x) + " " + str(notta) + " " + str(scl/2)+" 0 360 arc closepath"
			print "0.5 setlinewidth"
        		print "stroke"
			if toch == True:
				print "newpath"
        			print str(pos_x+shag/2) + " " + str(notta) + " " + "1.3 0 360 arc closepath"
				print "0 0 0 setgray fill"
				print "0.5 setlinewidth"
        			print "stroke"
			else:
				pass
		if dobd == True:
			if notta == Gd or notta == Ad:
				print "newpath"
				print str(pos_x-scl)+" "+ str(C) + " moveto"
				print str(pos_x+scl)+" "+ str(C) + " lineto"
				print str(pos_x-scl)+" "+ str(Ad) + " moveto"
				print str(pos_x+scl)+" "+ str(Ad) + " lineto"
				print "0.5 setlinewidth"
				print "stroke"
			elif notta == Bd or notta == C:
				print "newpath"
				print str(pos_x-scl)+" "+ str(C) + " moveto"
				print str(pos_x+scl)+" "+ str(C) + " lineto"
				print "0.5 setlinewidth"
				print "stroke"
		else:
			pass
		if dobup == True:
				print "newpath"
				print str(pos_x-10)+" "+ str(a) +" moveto"
				print str(pos_x+10)+" "+ str(a) +" lineto"
				print str(pos_x-10)+" "+ str(cup) + " moveto"
				print str(pos_x+10)+" "+ str(cup) + " lineto"
				print "0.5 setlinewidth"
				print "stroke"
		else:
			pass
		if dpal == True:
			print "newpath"
			print str(pos_x-scl/2)+" "+ str(notta)+ " moveto"
			print str(pos_x-scl/2)+" "+ str(notta-scl*4-plusp)+" lineto"
			print "0.8 setlinewidth"
			print "stroke"		
		else:
			print "newpath"
			print str(pos_x+scl/2)+" "+ str(notta)+ " moveto"
			print str(pos_x+scl/2)+" "+ str(notta+scl*4+plusp)+" lineto"
			print "0.8 setlinewidth"
			print "stroke"
		if alter == True:
			print "/Times-Roman findfont"
			print "11 scalefont"
			print "setfont"
			print "newpath"
			if trez == True:
				print str(pos_x-scl*1.9) +" " + str(notta-scl/2) + " " + " moveto"
				print "( "+ alt + " ) show"			
			else:
				print str(pos_x-scl*1.9) +" " + str(notta-scl/1.5) + " " + " moveto"
				print "( "+ alt + " ) show"
		else:
			pass
		if liga == True:
			print "/Times-Roman findfont"
			print "15 scalefont"
			print "setfont"
			print "newpath"
			print str(pos_x-scl*3.5) +" " + str(notta-scl*1.3) + " " + " moveto"
			print "(~) show"
		else:
			pass
		if single == True:
			if dpal == True:
				print "newpath"
				print str(pos_x-shag/1.1)+" "+ str(notta-scl*2)+ " moveto"
				print str(pos_x-shag*1.2)+" "+ str(notta-scl*4)+" lineto"
				print "1 setlinewidth"
				print "stroke"
			else:
				print "newpath"
				print str(pos_x+scl*0.5)+" "+ str(notta+scl*4)+ " moveto"
				print str(pos_x+scl*1.5)+" "+ str(notta+scl*1.8)
				print str(pos_x+scl*1)+" "+ str(notta+scl*1.6)
				print str(pos_x+scl*0.8)+" "+ str(notta+scl*0.5)
				print "curveto" 
				print "0.8 setlinewidth"
				print "stroke"
		else:	
			pass
		toch = False
		pos_x = pos_x + shag
		fill = True
		if plusp > 0:
			plusp = plusp - scl/1.5
		else:
			pass
		plusp = 0
#################################################nota###########################################
def per():
	if dpal == False:
			print "newpath"
			print str(one-scl*1.5)+" "+ str(onen+scl*4)+ " moveto"
			print str(two-scl*1.5)+" "+ str(twon+scl*4)+" lineto"
			print "3 setlinewidth"
			print "stroke"
	else:
			print "newpath"
			print str(one-scl*2.4)+" "+ str(onen-scl*4)+ " moveto"
			print str(two-scl*2.5)+" "+ str(twon-scl*4)+" lineto"
			print "3 setlinewidth"
			print "stroke"
def takt():
			global pos_x
			print "newpath"
			print str(pos_x+scl/2)+" "+ str(f)+ " moveto"
			print str(pos_x+scl/2)+" "+ str(f-scl*4)+" lineto"
			print "1.3 setlinewidth"
			print "stroke"
			pos_x = pos_x + shag*1.7
def bar():
			global pos_x
			print "newpath"
			print str(pos_x+scl/2)+" "+ str(f)+ " moveto"
			print str(pos_x+scl/2)+" "+ str(f-scl*4)+" lineto"
			print "1 setlinewidth"
			print "stroke"
			print "newpath"
			print str(pos_x+scl)+" "+ str(f)+ " moveto"
			print str(pos_x+scl)+" "+ str(f-scl*4)+" lineto"
			print "4 setlinewidth"
			print "stroke"
def pouse():
			print "/Times-Roman findfont"
			print "15 scalefont"
			print "setfont"
			print "newpath"
			print str(pos_x-15) +" " + str(G) + " " + " moveto"
			print "(R) show"	
def chords():
			print "/Times-Roman findfont"
			print "10 scalefont"
			print "setfont"
			print "newpath"
			print str(pos_x-scl*3) +" " + str(B+scl*6) + " " + " moveto"
			print "( " + chord + " ) show"
def obrab():
	global pos_x,notta,dobd,fill,i,one,onen,per,two,twon,dpal,dobup,plusp,vniz,trez,toch,bar,alt,chord,alter,single,sv
	i = 0
	for soch in mass:
		if soch == "||":
			bar()
			pos_x = pos_x + shag*2
			continue
		elif soch == "|":
			takt()
			continue
		#######chords
		elif soch[0] == '"':
			chord = soch
			sch = soch.replace('"','')
			chord = sch
			chords()
			continue
		else:
			pass
		for n in soch:
			if n[i] == "C":
					notta = C
					dobd = True
					dobup = False
					if trez == True:
						pos_x = pos_x - shag
					else:
						pass
			elif n[i] == "D":
					notta = D
					dobd = False
					dobup = False
					if trez == True:
						pos_x = pos_x - shag
					else:
						pass
			elif n[i] == "E":
					notta = E
					dobd = False
					dobup = False
					if trez == True:
						pos_x = pos_x - shag
					else:
						pass
			elif n[i] == "F":	
				if vniz == True:
					notta = Fd
					dobd = True
					dobup = False
					if trez == True:
						pos_x = pos_x - shag
					else:
						pass
				else:
					notta = F
					dobd = False
					dobup = False
					if trez == True:
						pos_x = pos_x - shag
					else:
						pass				
			elif n[i] == "G":
				if vniz == True:
					notta = Gd
					dobd = True
					dobup = False
					if trez == True:
						pos_x = pos_x - shag
					else:
						pass
				else:
					notta = G
					dobd = False
					dobup = False
					if trez == True:
						pos_x = pos_x - shag
					else:
						pass
			elif n[i] == "A":
				if vniz == True:
					notta = Ad
					dpal = False
					dobd = True
					dobup = False
					if trez == True:
						pos_x = pos_x - shag
					else:
						pass
				else:
					notta = A
					dobd = False
					dobup = False
					if trez == True:
						pos_x = pos_x - shag
					else:
						pass
			elif n[i] == "B":
				if vniz == True:
					notta = Bd
					pal = True
					dobd = True
					dobup = False
					if trez == True:
						pos_x = pos_x - shag
					else:
						pass
					
				else:
					notta = B
					pal = True
					dobd = False
					dobup = False
					if trez == True:
						pos_x = pos_x - shag
					else:
						pass
			elif n[i] == "d":
					notta = d
					dobd = False
					dobup = False
					pal = True
					if trez == True:
						pos_x = pos_x - shag
					else:
						pass
			elif n[i] == "e":
					if trez == True:
						notta = e
						dobd = False
						dobup = False
						pal = True
						pos_x = pos_x - shag
					else:
						notta = e
						dob = False
						pal = True
			elif n[i] == "f":
					if trez == True:
						notta = f
						dobd = False
						dobup = False
						pal = True
						pos_x = pos_x - shag
					else:
						notta = f
						dobd = False
						dobup = False
						pal = True
			elif n[i] == "g":
					if trez == True:
						notta = g
						dobd = False
						dobup = False
						pal = True
						pos_x = pos_x - shag
					else:
						notta = g
						dobd = False
						dobup = False
						pal = True
			elif n[i] == "a":
					if trez == True:
						notta = a
						pal = True
						dpal = True
						dopup = True
						dopd = False
						pos_x = pos_x - shag
					else:
						notta = a
						pal = True
						dpal = True
						dobup = True
						dopd = False
			elif n[i] == "[":
					trez = True
					continue
			elif n[i] == "c":
					if trez == True:
						notta = c
						dobd = False
						dobup = False
						pos_x = pos_x - shag
					else:
						notta = c
						dobd = False
						dobup = False
			elif n[i] == "]":
					trez = False
					continue
			elif n[i] == "4":
					fill = False
					continue
			elif n[i] == "6":
					fill = False
					toch = True
			elif n[i] == "3":
					fill = True
					toch = True
					nota()
			elif n[i] == "2":	
					continue
			elif n[i] == "1":
					single = True			
			elif n[i] == "^":
					alter = True
					alt = "#"
					continue
			elif n[i] == "_":
					alter = True
					alt = "b"
					continue
			elif n[i] == "=":
					alter = True
					alt = "="
					continue
			elif n[i] == "(":
					one = pos_x
					onen = notta
					continue
			elif n[i] == ")":
					two = pos_x
					twon = notta
					per()
					continue
			elif n[i] == "~":
					liga()
			elif n[i] == "u":
				dpal = False
			elif n[i] == "w":
				dpal = True
			elif n[i] == ",":
				vniz = True
				dopd = True
				continue
			elif n[i] == "'":
				vniz = False
				dopup = True
				continue
			elif n[i] == "+":
				plusp = plusp + scl/1.5
				continue
			elif n[i] == "-":
				plusp = plusp - scl/1.5
				continue
			elif n[i] == "r":
				pouse()
				pos_x = pos_x + shag/3
			elif n[i] == "p":
				pos_x = pos_x + shag
			else:
				pass
			nota()
			alter = False
			single = False
	i = i + 1
def stan():
	global pos_y
	i = 0
	while i < 5:
		print "newpath"
		print "10 "+str(pos_y)+" moveto"
		print "720 "+str(pos_y)+" lineto"
		print "0.5 setlinewidth"
		print "stroke"
		pos_y = pos_y - scl
		i = i + 1
def obs():
	if len(r_l) > 0:
		stan()
		noten()
		obrab()
	else:
		pass
massr()
obs()
readl()
massr()
pos_y = 60 * scl
pos_x = scl*3
obs()
readl()
massr()
pos_y = 45 * scl
pos_x = scl*3
obs()
readl()
massr()
pos_x = scl*3
pos_y = 30 * scl
obs()
f_o.close()
print "% ###################### OK #########################"
print "% ###################### OK #########################"
print "% ###################### OK #########################"
print "% ###################### OK #########################"
print "% ###################### OK #########################"
print "% ###################### OK #########################"
print "% ###################### OK #########################"
